package controller

import (
	"ollama-go/dto"
	"ollama-go/query"
	"ollama-go/service"

	"github.com/androidsr/sc-go/model"
	"github.com/androidsr/sc-go/sgin"
	"github.com/gin-gonic/gin"
)

func init() {
	sgin.AddRouter(ApiRequestConfigController{
		apiRequestConfigService: service.NewApiRequestConfigService(),
	})
}

type ApiRequestConfigController struct {
	apiRequestConfigService *service.ApiRequestConfigService
}

// 查询
// @Router [get] [/apirequestconfig/:id]
func (m ApiRequestConfigController) Get(c *gin.Context) any {
	id := c.Param("id")
	if id == "" {
		return model.NewFailDefault("ID不能为空")
	}
	return m.apiRequestConfigService.Get(id)
}

// 增加
// @Router [post] [/apirequestconfig]
func (m ApiRequestConfigController) Save(c *gin.Context, dto *dto.ApiRequestConfigDTO) any {
	dto.Id = ""
	return m.apiRequestConfigService.Save(dto)
}

// 修改
// @Router [put] [/apirequestconfig/edit]
func (m ApiRequestConfigController) UpdateById(c *gin.Context, dto *dto.ApiRequestConfigDTO) any {
	if dto.Id == "" {
		return model.NewFailDefault("ID不能为空")
	}
	dto.TenantId = c.GetString(USER)
	return m.apiRequestConfigService.UpdateById(dto)

}

// 删除
// @Router [delete] [/apirequestconfig/:id]
func (m ApiRequestConfigController) DeleteById(c *gin.Context) any {
	id := c.Param("id")
	if id == "" {
		return model.NewFailDefault("ID不能为空")
	}
	return m.apiRequestConfigService.DeleteById(id)
}

// 查询列表
// @Router [post] [/apirequestconfig/page]
func (m ApiRequestConfigController) QueryPage(c *gin.Context, query *query.ApiRequestConfigQueryDTO) any {
	return m.apiRequestConfigService.QueryPage(query)
}

// 分页下拉
// @Router [post] [/apirequestconfig/list]
func (m ApiRequestConfigController) QuerySelect(c *gin.Context, query *model.SelectQueryDTO) any {
	return m.apiRequestConfigService.QueryList(query)
}

// AI获取接口信息
// @Router [post] [/apirequestconfig/aiRecognitionApi]
func (m ApiRequestConfigController) AiRecognitionApi(c *gin.Context, dto *dto.ApiRequestDTO) any {
	if dto.ApiForm.FilePath == "" {
		return model.NewFailDefault("接口文件不能为空")
	}
	if dto.ApiForm.ApiName == "" {
		return model.NewFailDefault("接口名称不能为空")
	}
	return m.apiRequestConfigService.AiRecognitionApi(dto)
}

// 发送请求
// @Router [post] [/apirequestconfig/send]
func (m ApiRequestConfigController) Send(c *gin.Context, dto *dto.ApiRequestDTO) any {
	return m.apiRequestConfigService.Send(dto)
}
